# Contributor: Isaac Dunham <ibid.ag@gmail.com>
# Maintainer: Dominika Liberda <ja@sdomi.pl>
pkgname=xpdf
pkgver=4.04
pkgrel=0
pkgdesc="The classic X11 PDF viewer"
url="https://www.xpdfreader.com/"
arch="all"
license="GPL-2.0-or-later OR GPL-3.0-or-later"
depends="ghostscript-fonts"
makedepends="cmake qt5-qtbase-dev samurai"
subpackages="$pkgname-doc"
source="https://dl.xpdfreader.com/xpdf-$pkgver.tar.gz
	permissions.patch"

# secfixes:
#   4.03-r0:
#     - CVE-2020-25725
#     - CVE-2020-35376

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DSYSTEM_XPDFRC=/etc/xpdfrc \
		$CMAKE_CROSSOPTS
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	# delete pdf* utils and associated man pages that conflict with
	# poppler-utils.
	rm -f "$pkgdir"/usr/bin/pdf*
	rm -f "$pkgdir"/usr/share/man/man1/pdf*

	# install xpdfrc
	install -Dm644 doc/sample-xpdfrc "$pkgdir"/etc/xpdfrc
}

sha512sums="
a26b67a4b3d5a5a365153845bf72d77949e683ce26aaf4705b49194cb32bbc581617c3e9c37f74bf6c49480df06d49e8c38d41233966b6215eacf92591d4d9bf  xpdf-4.04.tar.gz
cf56bf9b4ccecc85fd34805454513b921bfe044442dad129178cde6f9ff2fae322bf0d71aaa69b9456aa0f41d639bc3a6aa2c7dcaae177013ac45e92f9fc3125  permissions.patch
"
